from rich.console import Console


# Define styles
console = Console()
console.print('Hello World!', style='magenta')
# 颜色格式：https://rich.readthedocs.io/en/latest/appendix/colors.html
console.print('Hello World!', style='5')
console.print("Hello World!", style="#af00ff")
console.print("Hello World!", style="rgb(175,0,255)")

console.print('DANGER', style='red on white')
console.print('DANGER, Will Robinson', style='blink bold italic strike underline red on white')
console.print('DANGER, [not bold]Will[/not bold] Robinson', style='bold red')# 使某些字取消style
console.print('Google',style='link https://google.com')# 超链接

# Style class
from rich.style import Style

console.print('Hello World!', style=Style(color='red', blink=True, bold=True))# 通过Style类调用的style会比直接string快一些，但只在第一次调用时快，后续因为rich缓存style所以速率相同
style = Style.parse('red blink bold')
console.print('Hello World!', style=style)

# Style Theme

from rich.theme import Theme
custom_theme = Theme({
    "info" : "dim cyan",
    "warning": "magenta",
    "danger": "bold red"
})
console = Console(theme=custom_theme)# 通过在创建console时指定theme，使得之后输出时更易调用设定好的格式
console.print("This is information", style="info")
console.print("Something terrible happened!", style="danger")
console.print('[warning]Hello World![\warning]')

read_theme = Theme.read('theme.cfg')
console = Console(theme = read_theme)
console.print("This is information", style="info")
console.print("Something terrible happened!", style="danger")
console.print('[warning]Hello World![\warning]')